
//package java_cup;

/** 
 * This class represents a part of a production which contains an
 * actionPart.  These are eventually eliminated from AllProdctions and converted
 * to trailing actions by factoring @out with a production that derives the
 * empty string (and ends with this actionPart).
 *
 * @see java_cup.production
 * @version last update: 11/25/95
 * @author Scott Hudson
 */

public class ActionPart : ProductionPart {

    /*-----------------------------------------------------------*/
    /*--- Constructors ------------------------------------------*/
    /*-----------------------------------------------------------*/

    /** Simple constructor. 
     * @param code_str string containing the actual user code.
     */
    public ActionPart(String codeStr)
        : base(/* never have a label on code */null) {
        _code_string = codeStr;
    }

    /*-----------------------------------------------------------*/
    /*--- (Access to) Instance Variables ------------------------*/
    /*-----------------------------------------------------------*/

    /** String containing code for the actionPart in question. */
    public String _code_string;

    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

    /** String containing code for the actionPart in question. */
    public String CodeString => _code_string;
    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

    ///** Set the code string. */
    //public void setCodeString(String newStr) { _code_string = newStr; }

    /*-----------------------------------------------------------*/
    /*--- General Methods ---------------------------------------*/
    /*-----------------------------------------------------------*/

    /** Override to report this object as an actionPart. */
    /*@Override*/
    public override bool IsAction => true;
    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

    /** Equality comparison for properly typed object. */
    public bool equals(ActionPart other) {
        /* compare the strings */
        return other != null && base.Equals(other) &&
           other.CodeString.Equals(CodeString);
    }

    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

    /** Generic equality comparison. */
    /*@Override*/
    public override bool Equals(Object? other) {
        if (!(other is ActionPart))
            return false;
        else
            return equals((ActionPart)other);
    }

    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

    /** Produce a hash code. */
    /*@Override*/
    public override int GetHashCode() {
        return base.GetHashCode() ^
           (CodeString == null ? 0 : CodeString.GetHashCode());
    }

    /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/

    /** Convert to a string.  */
    /*@Override*/
    public override string ToString() {
        return base.ToString() + "{" + CodeString + "}";
    }

    /*-----------------------------------------------------------*/
}
